#!/bin/sh
#
# This is the script for generating files for a specific Dalton test job.
#
# For the .check file ksh or bash is preferred, otherwise use sh
# (and hope it is not the old Bourne shell, which will not work)
#
if [ -x /bin/ksh ]; then
   CHECK_SHELL='#!/bin/ksh'
elif [ -x /bin/bash ]; then
   CHECK_SHELL='#!/bin/bash'
else
   CHECK_SHELL='#!/bin/sh'
fi


#######################################################################
#  TEST DESCRIPTION
#######################################################################
cat > walk_vibave2.info <<'%EOF%'
   walk_vibave2
   ------------
   Molecule:         HF
   Wave Function:    SCF / ANO (Atombasis)
   Test Purpose:     Vibrational average of shieldings
%EOF%

#######################################################################
#  MOLECULE INPUT
#######################################################################
cat > walk_vibave2.mol <<'%EOF%'
ATOMBASIS
Vibrational averaging of shieldings

Atomtypes=2 Nosymmetry        Integrals=0.10D-14
Charge=1.0 Atoms=1 Basis=ano-4 3 2 0
H          0.0000000000            0.0000000000            1.7497928937
Basis=ano-4 4 3 2 0 Charge=9.0 Atoms=1
F          0.0000000000            0.0000000000            0.0241892414
%EOF%

#######################################################################
#  DALTON INPUT
#######################################################################
cat > walk_vibave2.dal <<'%EOF%'
**DALTON INPUT
.WALK
*WALK
.VIBAVE
.DISPLAC
 0.05
.ECKART
 H          0.0000000000            0.0000000000            1.7243524476
 F          0.0000000000            0.0000000000            0.0255388031
**WAVE FUNCTIONS
.HF
*SCF INPUT
.THRESH
 1.0D-10
**START
.SHIELD
.PRINT
 4
*LINRES
.THRESH
1.0D-7
*RESPONSE
.THRESH
1.0D-6
**EACH STEP
.SHIELD
.PRINT
 4
*LINRES
.THRESH
1.0D-7
*RESPONSE
.THRESH
1.0D-6
**END OF DALTON INPUT
%EOF%
#######################################################################



#######################################################################

#######################################################################
#  CHECK SCRIPT
#######################################################################
echo $CHECK_SHELL >walk_vibave2.check
cat >>walk_vibave2.check <<'%EOF%'
log=$1

if [ `uname` = Linux ]; then
   GREPL="egrep -a -l"
elif [ `uname` = Darwin ]; then
   GREPL="egrep -a -l"
else
   GREPL="egrep -l"
fi

# Basis set
CRIT1=`$GREPL "H * 1 * 1\.0000 * 16 * 9 * \[7s3p\|3s2p\]" $log | wc -l`
CRIT2=`$GREPL "F * 1 * 9\.0000 * 43 * 23 * \[10s6p3d\|4s3p2d\]" $log | wc -l`
CRIT3=`$GREPL "total\: * 2 * 10\.0000 * 59 * 32" $log | wc -l`
CRIT4=`$GREPL "Spherical harmonic basis used\." $log | wc -l`
TEST[1]=`expr	$CRIT1 \+ $CRIT2 \+ $CRIT3 \+ $CRIT4`
CTRL[1]=4
ERROR[1]="ATOMBASIS NOT READ CORRECTLY"

# Geometry
CRIT1=`$GREPL "3 * z * 1\.7497928937" $log | wc -l`
CRIT2=`$GREPL "6 * z * (0| )\.0241892414" $log | wc -l`
TEST[2]=`expr	$CRIT1 \+ $CRIT2`
CTRL[2]=2
ERROR[2]="GEOMETRY NOT READ CORRECTLY"

# Numerical differentiation
CRIT1=`$GREPL "Walk type\: Numerical differentiation" $log | wc -l`
CRIT2=`$GREPL "Vibrational averaging of * molecular properties at an effective geometry" $log | wc -l`
CRIT3=`$GREPL "Molecular properties transformed to the following Eckart frame" $log | wc -l`
CRIT4=`$GREPL "H * 0?\.0000000000 * 0?\.0000000000 * 1\.7243524476" $log | wc -l`
CRIT5=`$GREPL "F * 0?\.0000000000 * 0?\.0000000000 * 0?\.0255388031" $log | wc -l`
TEST[3]=`expr	$CRIT1 \+ $CRIT2 \+ $CRIT3 \+ $CRIT4 \+ $CRIT5`
CTRL[3]=5
ERROR[3]="NUMERICAL DIFFERENTIATION NOT SET UP CORRECTLY"

# Initial gradient
CRIT1=`$GREPL "H * (0| |\-0|\-)\.0000000000 * (0| |\-0|\-)\.0000000000 * 0?\.018485145[0-9]" $log | wc -l`
CRIT2=`$GREPL "F * (0| |\-0|\-)\.0000000000 * (0| |\-0|\-)\.0000000000 * -0?\.018485145[0-9]" $log | wc -l`
TEST[4]=`expr	$CRIT1 \+ $CRIT2`
CTRL[4]=2
ERROR[4]="INITIAL GRADIENT NOT CORRECT"

# Initial Hessian
CRIT1=`$GREPL "H * x * 0?\.01071[0-9]" $log | wc -l`
CRIT2=`$GREPL "H * y * -?0?\.000000 * 0?\.01071[0-9]" $log | wc -l`
CRIT3=`$GREPL "H * z * -?0?\.000000 * -?0?\.000000 * 0?\.65526[0-9]" $log | wc -l`
CRIT4=`$GREPL "F * x * -0?\.01071[0-9] * -?0?\.000000 * -?0?\.000000 * 0?\.01071[0-9]" $log | wc -l`
CRIT5=`$GREPL "F * y * -?0?\.000000 * -0?\.01071[0-9] * -?0?\.000000 * -?0?\.000000 * 0?\.01071[0-9]" $log | wc -l`
CRIT6=`$GREPL "F * z * -?0?\.000000 * -?0?\.000000 * -0?\.65526[0-9] * -?0?\.000000 * -?0?\.000000 * 0?\.65526[0-9]" $log | wc -l`
TEST[5]=`expr	$CRIT1 \+ $CRIT2 \+ $CRIT3 \+ $CRIT4 \+ $CRIT5 \+ $CRIT6`
CTRL[5]=6
ERROR[5]="INITIAL HESSIAN NOT CORRECT"

# Initial shielding for hydrogen
CRIT1=`$GREPL "Shielding constant\: * 29\.062[0-9] ppm" $log | wc -l`
CRIT2=`$GREPL "Anisotropy\: * 22\.984[0-9] ppm" $log | wc -l`
CRIT3=`$GREPL "S parameter\: * 22\.984[0-9] ppm" $log | wc -l`
TEST[6]=`expr	$CRIT1 \+ $CRIT2 \+ $CRIT3`
CTRL[6]=3
ERROR[6]="INITIAL CHEMICAL SHIELDING FOR HYDROGEN NOT CORRECT"

# Initial shielding for fluorine
CRIT1=`$GREPL "Shielding constant\: * 414\.925[0-9] ppm" $log | wc -l`
CRIT2=`$GREPL "Anisotropy\: * 100\.277[0-9] ppm" $log | wc -l`
CRIT3=`$GREPL "S parameter\: * 100\.277[0-9] ppm" $log | wc -l`
TEST[7]=`expr	$CRIT1 \+ $CRIT2 \+ $CRIT3`
CTRL[7]=3
ERROR[7]="INITIAL CHEMICAL SHIELDING FOR FLUORINE NOT CORRECT"

# Initial shielding summary
CRIT1=`$GREPL "\@1 H * 29\.062[0-9] * 21\.050[0-9] * 8\.012[0-9] * 1\.0000 * 22\.984[0-9] * 22\.984[0-9] * 0?\.0000" $log | wc -l`
CRIT2=`$GREPL "\@1 F * 414\.925[0-9] * 478\.027[0-9] * \-63\.102[0-9] * 1\.0000 * 100\.277[0-9] * 100\.277[0-9] * 0?\.0000" $log | wc -l`
CRIT3=`$GREPL "\@2 H * 29\.062[0-9] * 21\.050[0-9] * 8\.012[0-9] * 22\.984[0-9] * 0?\.0000 * 22\.984[0-9] * 0?\.0000" $log | wc -l`
CRIT4=`$GREPL "\@2 F * 414\.925[0-9] * 478\.027[0-9] * \-63\.102[0-9] * 100\.277[0-9] * 0?\.0000 * 100\.277[0-9] * 0?\.0000" $log | wc -l`
TEST[8]=`expr	$CRIT1 \+ $CRIT2 \+ $CRIT3 \+ $CRIT4`
CTRL[8]=4
ERROR[8]="SUMMARY OF INITIAL SHIELDINGS NOT CORRECT"

# Projected gradient
CRIT1=`$GREPL "Norm of projected gradient * 0?\.02614[0-9]" $log | wc -l`
TEST[9]=`expr	$CRIT1`
CTRL[9]=1
ERROR[9]="PROJECTED GRADIENT NOT CORRECT"

# Projected Hessian
CRIT1=`$GREPL "3 * (0| |\-0|\-)\.00000000 * (0| |\-0|\-)\.00000000 * (0| )\.655267.[0-9] * (0| |\-0|\-)\.00000000" $log | wc -l`
CRIT2=`$GREPL "6 * (0| |\-0|\-)\.00000000 * (0| |\-0|\-)\.00000000 * (\-0|\-)\.655267.[0-9] * (0| |\-0|\-)\.00000000" $log | wc -l`
CRIT3=`$GREPL "3 * (\-0|\-)\.655267.[0-9]" $log | wc -l`
CRIT4=`$GREPL "6 * (0| )\.655267.[0-9]" $log | wc -l`
TEST[10]=`expr	$CRIT1 \+ $CRIT2 \+ $CRIT3 \+ $CRIT4`
CTRL[10]=4
ERROR[10]="PROJECTED HESSIAN NOT CORRECT"

# Energy at effective geometry
CRIT1=`$GREPL "Energy at effective geometry\: * \-100\.056552108[0-9]" $log | wc -l`
TEST[11]=`expr	$CRIT1`
CTRL[11]=1
ERROR[11]="ENERGY AT EFFECTIVE GEOMETRY NOT CORRECT"

# Gradient at effective geometry
CRIT1=`$GREPL "1 * (0| |\-0|\-)\.00000000 * (0| |\-0|\-)\.00000000 * (0| )\.018485.[0-9] * (0| |\-0|\-)\.00000000" $log | wc -l`
CRIT2=`$GREPL "1 * (\-0|\-)\.018485.[0-9]" $log | wc -l`
TEST[12]=`expr	$CRIT1 \+ $CRIT2`
CTRL[12]=2
ERROR[12]="GRADIENT AT EFFECTIVE GEOMETRY NOT CORRECT"

# Dipole moment at effective geometry
CRIT1=`$GREPL "1 * (\-0?|0?)\.00000000 * (\-0?|0?)\.00000000 * 0?\.7593853[0-9]" $log | wc -l`
TEST[13]=`expr	$CRIT1`
CTRL[13]=1
ERROR[13]="DIPOLE MOMENT AT EFFECTIVE GEOMETRY NOT CORRECT"

# Energy at first displacement
CRIT1=`$GREPL "Final * HF energy\: * \-100\.0548051557.." $log | wc -l`
TEST[14]=`expr	$CRIT1`
CTRL[14]=1
ERROR[14]="ENERGY AT FIRST DISPLACEMENT NOT CORRECT"

# Numerical differentiation done
CRIT1=`$GREPL "All displacements are now done \- numerical differentiation is complete\." $log | wc -l`
TEST[15]=`expr	$CRIT1`
CTRL[15]=1
ERROR[15]="NUMERICAL DIFFERENTIATION NOT COMPLETED"

# Dipole moment second derivatives
CRIT1=`$GREPL "1 * (\-0|\-|0| )\.000000 * (\-0|\-|0| )\.000000 * 0?\.10951[0-9]" $log | wc -l`
TEST[16]=`expr	$CRIT1`
CTRL[16]=1
ERROR[16]="DIPOLE MOMENT SECOND DERIVATIVES NOT CORRECT"

# Nuclear shielding tensor second derivatives for hydrogen
CRIT1=`$GREPL "1 * 32\.8[4-8][0-9] * (\-0|\-|0| )\.0[0-9][0-9] * (\-0|\-|0| )\.00[0-9] * (\-0|\-|0| )\.0[0-9][0-9] * 32\.8[3-9][0-9] * (\-0|\-|0| )\.00[0-9] * (\-0|\-|0| )\.00[0-9] * (\-0|\-|0| )\.00[0-9] * 62\.46[4-6]" $log | wc -l`
TEST[17]=`expr	$CRIT1`
CTRL[17]=1
ERROR[17]="NUCLEAR SHIELDING TENSOR SECOND DERIVATIVES FOR HYDROGEN NOT CORRECT"

# Nuclear shielding tensor second derivatives for fluorine
CRIT1=`$GREPL "1 * \-60[3-7]\.[0-9][0-9][0-9] * (\-[0-2]|\-|[0-2]| )\.[0-9][0-9][0-9] * (\-0|\-|0| )\.[0-2][0-9][0-9] * (\-[0-3]|\-|[0-3]| )\.[0-9][0-9][0-9]\-60[3-6]\.[0-9][0-9][0-9] * (\-0|\-|0| )\.[0-9][0-9][0-9] * (\-0|\-|0| )\.00[0-9] * (\-0|\-|0| )\.00[0-9] * 5\.92[7-9]" $log | wc -l`
TEST[18]=`expr	$CRIT1`
CTRL[18]=1
ERROR[18]="NUCLEAR SHIELDING TENSOR SECOND DERIVATIVES FOR FLUORINE NOT CORRECT"

# Vibrationally averaged dipole moment
CRIT1=`$GREPL "Z * 0?\.7593853[0-9] * 0?\.00077[3-4][0-9][0-9] * 0?\.7601(60|59)[0-9][0-9]" $log | wc -l`
TEST[19]=`expr	$CRIT1`
CTRL[19]=1
ERROR[19]="VIBRATIONALLY AVERAGED DIPOLE MOMENT NOT CORRECT"

# Vibrationally averaged nuclear magnetic shielding constants for hydrogen
CRIT1=`$GREPL "Bxmx * 21\.40068.* * 0?\.232[0-4].* * 21\.632[6-8]" $log | wc -l`
CRIT2=`$GREPL "Bymy * 21\.40068.* * 0?\.232[0-4].* * 21\.632[6-8]" $log | wc -l`
CRIT3=`$GREPL "Bzmz * 44\.38498.* * 0?\.441[2-4].* * 44\.826[2-4]" $log | wc -l`
TEST[20]=`expr	$CRIT1 \+ $CRIT2 \+ $CRIT3`
CTRL[20]=3
ERROR[20]="VIBRATIONALLY AVERAGED NUCLEAR SHIELDING FOR HYDROGEN NOT CORRECT"

# Vibrationally averaged nuclear magnetic shielding constants for fluorine
CRIT1=`$GREPL "Bxmx * 381\.49939.* * \-4\.26[6-9].* * 377\.23[0-3]" $log | wc -l`
CRIT2=`$GREPL "Bymy * 381\.49939.* * \-4\.26[6-9].* * 377\.23[0-3]" $log | wc -l`
CRIT3=`$GREPL "Bzmz * 481\.7771[56].* * 0?\.041[8-9].* * 481\.8190[0-9]" $log | wc -l`
TEST[21]=`expr	$CRIT1 \+ $CRIT2 \+ $CRIT3`
CTRL[21]=3
ERROR[21]="VIBRATIONALLY AVERAGED NUCLEAR SHIELDING FOR FLUORINE NOT CORRECT"

# Final energy
CRIT1=`$GREPL "Final * HF energy\: * \-100\.05655210811[0-9]" $log | wc -l`
TEST[22]=`expr	$CRIT1`
CTRL[22]=1
ERROR[22]="FINAL ENERGY NOT CORRECT"

PASSED=1
for i in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
do
   if [ ${TEST[i]} -ne ${CTRL[i]} ]; then
     echo "${ERROR[i]} ( test = ${TEST[i]}; control = ${CTRL[i]} ); "
     PASSED=0
   fi
done

if [ $PASSED -eq 1 ]
then
  echo TEST ENDED PROPERLY
  exit 0
else
  echo THERE IS A PROBLEM
  exit 1
fi

%EOF%
#######################################################################
